//
//  SleepHearRateCell.swift
//  DaRings
//
//  Created by 尹琼 on 2022/11/4.
//

import UIKit
import MYModule

import RxSwift
import RxCocoa

class SleepHearRateCell: SleepAverageCell {
    
    var learnMoreHandle: (() ->Void)?
    
    
    override func makeUI() {
        super.makeUI()
       
        bgView.addSubview(hrvHintView)
        bgView.addSubview(descLabel)
        
        averageView.snp.remakeConstraints { make in
            make.top.left.right.equalToSuperview()
        }
        
        
        hrvHintView.snp.makeConstraints { make in
            make.top.equalTo(averageView.snp.bottom).offset(20)
            make.leading.trailing.equalToSuperview()
        }
        
        descLabel.snp.makeConstraints { make in
            make.top.equalTo(hrvHintView.snp.bottom).offset(16)
            make.leading.equalToSuperview().offset(20)
            make.centerX.equalToSuperview()
            make.bottom.equalToSuperview().offset(-20)
        }
        
        
        averageView.fillChartView.titleLabel.text = "sleep_average_heart_rate".language
        averageView.fillChartView.unitLabel.text = "heart_rate_bpm".language
        
        averageView.fillChartView.maxHRVView.iconImageView.image = UIImage(named: "ic_sleep_max")
        averageView.fillChartView.maxHRVView.unitLabel.text = "heart_rate_bpm".language
        averageView.fillChartView.maxHRVView.descLabel.text = "sleep_max_hr".language
        
        averageView.fillChartView.minHRVView.iconImageView.image = UIImage(named: "ic_sleep_min")
        averageView.fillChartView.minHRVView.unitLabel.text = "heart_rate_bpm".language
        averageView.fillChartView.minHRVView.descLabel.text = "sleep_min_hr".language
        
        hrvHintView.iconImageView.image = UIImage(named: "ic_sleep_tips")
        hrvHintView.descLabel.text = "sleep_heart_rate_patterns".language
        descLabel.text = "sleep_heart_rate_patterns_description".language
        hrvHintView.statusLabel.text = "sleep_learn_more".language
        hrvHintView.statusLabel.textColor = UIColor.theme
        
        hrvHintView.statusLabel.rx.tapGesture().subscribe(onNext: {[weak self] _ in
            
            self?.learnMoreHandle?()
            
        }).disposed(by: rx.disposeBag)
        
       
    }
    
    
    public lazy var hrvHintView: SleepHeartHintView = {
        //    sleep_excellent    Excellent    优
        //    sleep_good    Good    良
        //    sleep_medium    Medium    中
        //    sleep_poor    Poor    差
        let hrvHintView = SleepHeartHintView()
        hrvHintView.setSleepStatus(stateStr: "sleep_medium".language)
        return hrvHintView
    }()
    
    public lazy var descLabel: Label = {
        let descLabel = Label()
        descLabel.text = "sleep_apnea_risk_description".language
        descLabel.textColor = UIColor.assist_A9A9A9
        descLabel.numberOfLines = 0
        descLabel.font = Fonts.systemFont(ofSize: 12)
        return descLabel
    }()
    

    

}
